import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

/**
 * The game's main setting screen
 * @author Akshay
 *
 */
public class SettingsState extends BasicGameState implements IButtonListener {
	
	int stateID = 0;
	
	private LabeledButton backButton;
	
	private boolean enterMainMenuFlag = false;
	
	public SettingsState(int ID){
		stateID = ID;
	}
	
	@Override
	public void init(GameContainer container, StateBasedGame game) throws SlickException {
		backButton  = new LabeledButton(Resources.back_arrow, Resources.back_arrow_hover, Resources.back_arrow_down, 0, container.getHeight()-Resources.back_arrow.getHeight(), null, this);
	}
	
	@Override
	public void enter(GameContainer container, StateBasedGame game) throws SlickException {
		enterMainMenuFlag = false;
	}

	@Override
	public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
		//draw background
		Resources.image_mainmenu_background.draw(0,0);
		Resources.image_settings_title.draw((container.getWidth()-Resources.image_settings_title.getWidth())/2, 50);
		
		//draw back button
		backButton.render(container, game, g);
	}

	@Override
	public void update(GameContainer container, StateBasedGame game, int delta)throws SlickException {			
		
		backButton.update(container, game);
		
		if(enterMainMenuFlag){
			game.enterState(Game.STATE_MAINMENU);
			enterMainMenuFlag = false;
		}
		
	}
	
	@Override
	public void keyReleased(int key, char c){
		//Escape key goes to mainmenu
		if(key == Input.KEY_ESCAPE){
			enterMainMenuFlag = true;
		}
	}
	
	@Override
	public void buttonClicked(LabeledButton source) {
		if(source == backButton){
			enterMainMenuFlag = true;
		}
		
	}

	@Override
	public int getID() {
		return stateID;
	}
}
